<template>
  <div @click="$emit('like', obj.dogName)">
    <img
      src="http://nwzimg.wezhan.cn/contents/sitefiles2029/10146688/images/21129958.jpg"
      alt=""
    />
    <p @click.stop="fn" :style="{ background: bgColor }">{{ obj.dogName }}</p>
  </div>
</template>

<script>
export default {
  props: {
    obj: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      bgColor: "",
    };
  },
  methods: {
    fn() {
      this.bgColor = `rgb(${this.genRandomColor()},${this.genRandomColor()},${this.genRandomColor()})`;
    },
    genRandomColor() {
      return Math.floor(Math.random() * 256);
    },
  },
};
</script>

<style scoped>
div {
  width: 200px;
  border: 1px solid black;
  text-align: center;
  float: left;
}

div img {
  width: 100%;
  height: 200px;
}
</style>
